	function CourseWrite(){
		this.objComm = null;
		this.objRegist = null;
		this.objCourseSelectList = null;
	};
	
	CourseWrite.prototype = {
		
		onPageShow: function() {
				this._init();
			}
			, _init: function(){

				$("a").attr("href","");
				
				this._role();
			}
			, _start: function(){
				
				this.objCourseSelectList = new clsCourseSelectList();
				this.objComm = new CourseWrite_Comm();
				this.objRegist = new CourseRegist_Comm();
				
				this.spinStart();
				
				this.objCourseSelectList.$getCheckBoxObj().find("input[type=radio]:eq(0)").prop("checked", true).checkboxradio("refresh");
				
				this.objCourseSelectList.$getLayer().find("li:eq(1)>div:eq(2)").hide();
				this.objCourseSelectList.$getLayer().find("li:eq(1)>div:eq(3)").hide();
				
				this.objComm.getAreaSelect();
	      
	      this._bind();
			}
			, _bind: function(){
				var thisClass = this;
				
				//골프장선택 - 직적입력 클릭이벤트
				this.objCourseSelectList.$getCheckBoxObj().find("input[type=radio]").click(function(){
					var idx = thisClass.objCourseSelectList.$getCheckBoxObj().find("input[type=radio]").index($(this));
					if(idx == 0){
						thisClass.objCourseSelectList.$getLayer().find("li:eq(1)>div:eq(0)").show();
						thisClass.objCourseSelectList.$getLayer().find("li:eq(1)>div:eq(1)").show();
						thisClass.objCourseSelectList.$getLayer().find("li:eq(1)>div:eq(2)").hide();
						thisClass.objCourseSelectList.$getLayer().find("li:eq(1)>div:eq(3)").hide();
						thisClass.objComm.setSearchRequest("직접작성", "N");
					}else{
						thisClass.objCourseSelectList.$getLayer().find("li:eq(1)>div:eq(0)").hide();
						thisClass.objCourseSelectList.$getLayer().find("li:eq(1)>div:eq(1)").hide();
						thisClass.objCourseSelectList.$getLayer().find("li:eq(1)>div:eq(2)").show();
						thisClass.objCourseSelectList.$getLayer().find("li:eq(1)>div:eq(3)").show();
						thisClass.objComm.setSearchRequest("직접작성", "Y");
					}
				});
				
				//등록 이벤트
				$("section#course_write div.bt_form").click(function(event){
					//골프장 선택
					var select1 = thisClass.objCourseSelectList.$getAreaSelectObj().val();
					var select2 = thisClass.objCourseSelectList.$getGolfSelectObj().val();
					var select3 = thisClass.objCourseSelectList.$getCourseSelectObj().val();
					var select4 = thisClass.objCourseSelectList.$getHoleSelectObj().val();
					
					//직접입력
					var golfText = thisClass.objCourseSelectList.$getLayer().find("li:eq(1)>div:eq(2) input[type=text]:eq(0)").val();
					var courseText = thisClass.objCourseSelectList.$getLayer().find("li:eq(1)>div:eq(2) input[type=text]:eq(1)").val();
					var holeText = thisClass.objCourseSelectList.$getLayer().find("li:eq(1)>div:eq(3) input[type=text]").val();
					
					var titleText = thisClass.objCourseSelectList.$getLayer().find("li:eq(2) input").val();
					var contentsText = thisClass.objCourseSelectList.$getLayer().find("li:eq(3) textarea").val();
					
					var userWriteYn = thisClass.objComm.getSearchRequest("직접작성");
					
					var imageInfo = thisClass.objCourseSelectList.imageData;
					
					if(userWriteYn == "Y"){//직접입력시
						if(!golfText){ alert("골프장을 입력하시기 바랍니다."); return; }
						if(!courseText){ alert("코스를 입력하시기 바랍니다."); return; }
						if(!holeText){ alert("홀을 입력하시기 바랍니다."); return; }
						thisClass.objRegist.setWriteRequest("골프장명", golfText);
						thisClass.objRegist.setWriteRequest("코스명", courseText);
						thisClass.objRegist.setWriteRequest("홀정보", holeText);
					}else{//골프장 선택시
						if(!select1){ alert("권역을 선택하시기 바랍니다."); return; }
						if(!select2){ alert("골프장을 선택하시기 바랍니다."); return; }
						if(!select3){ alert("코스를 선택하시기 바랍니다."); return; }
						if(!select4){ alert("홀을 선택하시기 바랍니다."); return; }
						thisClass.objRegist.setWriteRequest("권역키", thisClass.objComm.getSearchRequest("지역키"));
						thisClass.objRegist.setWriteRequest("골프장키", thisClass.objComm.getSearchRequest("골프장키"));
						thisClass.objRegist.setWriteRequest("코스키", thisClass.objComm.getSearchRequest("코스키"));
						thisClass.objRegist.setWriteRequest("홀번호", thisClass.objCourseSelectList.$getHoleSelectObj().val());
					}
					
					if(!titleText){ alert("제목을 입력하시기 바랍니다."); return; }
					if(!contentsText){ alert("상세내역을 입력하시기 바랍니다."); return; }
					
					if(imageInfo.length > 0){
						var image = _util.nvl(imageInfo[0]["이미지"]).replace('/data/msp300/dl/files/free/admin/notice/', 'http://www.golfinsns.com/_course_super_img/');
						contentsText = "<p><img src='" + image + "'/></p>" + contentsText;
					}
					
					thisClass.objRegist.setWriteRequest("제목", titleText);
					thisClass.objRegist.setWriteRequest("내용", contentsText);
					thisClass.objRegist.setWriteRequest("직접입력여부", userWriteYn);
					
					thisClass.objRegist.insertCourse();
					
				});
				
				//등록 완료 이벤트
				$(this.objRegist).bind("evtFinishInsertCourse", function(event, resData){
					alert(resData["메세지"]);
					$.mobile.changePage("course.html", "slide", true);
				});
				
				//권역 SelectBox
				$(this.objComm).bind("evtFinishAreaSelect", function(event){
					var listData = thisClass.objComm.getAreaSelectData();
					thisClass.objCourseSelectList.setAreaList(listData);
					thisClass.spinEnd();
				});
				
				//골프장 SelectBox
				$(this.objComm).bind("evtFinishGolfSelect", function(event){
					var listData = thisClass.objComm.getGolfSelectData();
					thisClass.objCourseSelectList.setGolfList(listData);
					thisClass.spinEnd();
				});
				
				//코스 SelectBox
				$(this.objComm).bind("evtFinishCourseSelect", function(event){
					var listData = thisClass.objComm.getCourseSelectData();
					thisClass.objCourseSelectList.setCourseList(listData);
					thisClass.spinEnd();
				});
				//이미지
				$(this.objComm).bind("evtFinishHoleImage", function(event){
					var listData = thisClass.objComm.getHoleSelectData();
					if(listData.length == 0){
						alert("이미지가 없습니다.");
						thisClass.spinEnd();
						return;
					}
					thisClass.objCourseSelectList.setHoleImage(listData);
					thisClass.spinEnd();
				});
				
				//권역선택 SelectBox
				this.objCourseSelectList.$getAreaSelectObj().change(function(){
					var cnt = thisClass.objCourseSelectList.$getAreaSelectObj().val();
					var listData = thisClass.objComm.getAreaSelectData();
					if(cnt){
						thisClass.spinStart();
						thisClass.objComm.setSearchRequest("지역키", listData[cnt]["아이디"]);
					}
					thisClass.objComm.getGolfSelect();
				});
				
				//골프장 선택 SelectBox
				this.objCourseSelectList.$getGolfSelectObj().change(function(event){
					var cnt = thisClass.objCourseSelectList.$getGolfSelectObj().val();
					var listData = thisClass.objComm.getGolfSelectData();
					if(cnt){
						thisClass.spinStart();
						thisClass.objComm.setSearchRequest("골프장키", listData[cnt]["골프장키"]);
					}
					thisClass.objComm.getCourseSelect();
				});
				
				//코스 선택 SelectBox
				this.objCourseSelectList.$getCourseSelectObj().change(function(event){
					var cnt = thisClass.objCourseSelectList.$getCourseSelectObj().val();
					var listData = thisClass.objComm.getCourseSelectData();
					if(cnt){
						thisClass.spinStart();
						thisClass.objComm.setSearchRequest("코스키", listData[cnt]["코스키"]);
						thisClass.objCourseSelectList.setHoleList(listData[cnt]["홀갯수"]);
						thisClass.spinEnd();
					}
				});
				
				//이미지 삽입
				this.objCourseSelectList.$getLayer().find("li:eq(1)>div:eq(1) div.ui-block-b a").click(function(){
					var course = thisClass.objCourseSelectList.$getCourseSelectObj().val();
					var hole   = thisClass.objCourseSelectList.$getHoleSelectObj().val();
					if(!course){
						alert("코스를 선택해주세요.");
						return;
					}
					if(!hole){
						alert("홀을 선택해주세요.");
						return;
					}
					thisClass.spinStart();
					thisClass.objComm.setSearchRequest("홀", hole);
					thisClass.objComm.getHoleImage();
				});
				
				//직접선택 이미지 삽입
				this.objCourseSelectList.$getLayer().find("li:eq(1)>div:eq(3) div.ui-block-b a").click(function(){
					alert("이미지 삽입");
				});
				
				//이미지 삭제
				this.objCourseSelectList.$getLayer().find("li:eq(1) div.img_input button").click(function(){
					thisClass.objCourseSelectList.deleteHoleImage();
				});
			}
			, _role: function(){
				if(!_util.getLogin("로그인")){
					//alert("로그인 후 이용하실 수 있습니다.");		    			
					this.goNavi("../course/course_write.html");		
					return;
				}else {
					this._start();	    		
				}
	   	}
			, goNavi: function(rPage){			
				_gf.LOGIN_DATA.loginAfterUrl = rPage;
				$.mobile.changePage("../member/login.html","slide",true);
			}
			, spinStart: function(){
				$.mobile.showPageLoadingMsg();
			}
			, spinEnd: function(){
				$.mobile.hidePageLoadingMsg();
			}
		
	}
	
	
	/*============= 등록 =============*/
	function CourseRegist_Comm(){
		this.writeRequest = null;
		
		this._init();
	}
	
	CourseRegist_Comm.prototype = {
		_init: function(){
			this.writeRequest = {
				"권역키": null
				, "골프장키": null
				, "코스키": null
				, "홀번호": null
				, "직접입력여부": null
				, "제목": null
				, "내용": null
				, "골프장명": null
				, "코스명": null
				, "홀정보": null
			}
		}
		, insertCourse: function(){
			var thisClass = this;
			var objJson = new MJson();
			var cm = new ConnectionManager();
			
			objJson.putClient("userid", _util.getLogin("아이디"));
			objJson.putPub(MJson.PUB.SID, "KB001");
			objJson.putPub(MJson.PUB.SERVICENAME, "regKnowhowBoard");
			
			if(this.getWriteRequest("직접입력여부") == "Y"){
				objJson.putParameter("golfclub_data", this.getWriteRequest("골프장명"));
				objJson.putParameter("course_data", this.getWriteRequest("코스명"));
				objJson.putParameter("hole_data", this.getWriteRequest("홀정보"));
			}else{
				objJson.putParameter("districts", this.getWriteRequest("권역키"));
				objJson.putParameter("golfclub_seq", this.getWriteRequest("골프장키"));
				objJson.putParameter("course_seq", this.getWriteRequest("코스키"));
				objJson.putParameter("hole_no", this.getWriteRequest("홀번호"));
			}
			objJson.putParameter("userWriteYn", this.getWriteRequest("직접입력여부"));
			objJson.putParameter("title", this.getWriteRequest("제목"));
			objJson.putParameter("content", this.getWriteRequest("내용"));
			objJson.putParameter("notice_yn", "N");
			
			cm.requestGet(objJson.getJsonString(), function(ret){
				var resData = {
					"응답코드": (ret["msp"]["contents"]["serviceResult"]=="00000"?true:false)
					, "메세지": _util.getResultMsg(ret)
				}
				
				$(thisClass).trigger("evtFinishInsertCourse", resData);
			}, function($err) {
				alert($err);
			});
			
		}
		, setWriteRequest: function(key,val){
			this.writeRequest[key] = val;
		}
		, getWriteRequest: function(key){
			return this.writeRequest[key];
		}
	}
	
	/*============= 조회 =============*/
	function CourseWrite_Comm(){
		this.searchRequest = null;
		this.areaList = null;
		this.golfList = null;
		this.courseList = null;
		this.holeList = null;
		
		this._init();
	}
	
	CourseWrite_Comm.prototype = {
		_init: function(){
			this.searchRequest = {
				"지역키": null
				, "골프장키": null
				, "코스키": null
				, "홀": null
				, "직접작성": "N"
			}
		}
		/*------------------------- 권역정보 -------------------------*/
		, getAreaSelect: function(){
			
			var thisClass = this;
			var objJson = new MJson();
			var cm = new ConnectionManager();
			
			objJson.putPub(MJson.PUB.SID, "JR001");
			objJson.putPub(MJson.PUB.SERVICENAME, "getSelectRegion");
			objJson.putPub(MJson.PUB.LISTCOUNT, 9999);
			objJson.putPub(MJson.PUB.CURRPAGENO, 1);
			
			cm.requestGet(objJson.getJsonString(), function($jsonData){
				
				var res = $jsonData["msp"]["contents"]["items"];
				thisClass.areaList = [];
				if(res){
					if(!res.length){
						res = new Array(res);	
					}
					
					for(var i=0;i<res.length;++i){
						var obj = res;
							thisClass.areaList.push({
								"아이디": obj[i].value
								, "지역정보명": obj[i].cname
							});
					}
				}
				$(thisClass).trigger("evtFinishAreaSelect");
			}, function($err) {
				alert($err);
			});
		}
		/*------------------------- 골프장정보 -------------------------*/
		, getGolfSelect: function(){
			var thisClass = this;
			var objJson = new MJson();
			var cm = new ConnectionManager();
			
			objJson.putPub(MJson.PUB.SID, "KB001");
			objJson.putPub(MJson.PUB.SERVICENAME, "getNationalGolfclubList");
			
			objJson.putParameter("districts", this.getSearchRequest("지역키"));
			
			cm.requestGet(objJson.getJsonString(), function($jsonData){
				
				var res = $jsonData["msp"]["contents"]["items"];
				thisClass.golfList = [];
				if(res){
					if(!res.length){
						res = new Array(res);	
					}
					for(var i=0;i<res.length;++i){
						var obj = res;
							thisClass.golfList.push({
								"골프장키": obj[i].golfclub__seq
								, "골프장명": obj[i].golfclub__name
							});
					}
				}
				$(thisClass).trigger("evtFinishGolfSelect");
			}, function($err) {
				alert($err);
			});
		}
		/*------------------------- 코스정보 -------------------------*/
		, getCourseSelect: function(){
			var thisClass = this;
			var objJson = new MJson();
			var cm = new ConnectionManager();
			
			objJson.putPub(MJson.PUB.SID, "KB001");
			objJson.putPub(MJson.PUB.SERVICENAME, "getNationalGolfclubCourseList");
			
			objJson.putParameter("golfclub_seq", this.getSearchRequest("골프장키"));
			
			cm.requestGet(objJson.getJsonString(), function($jsonData){
				
				var res = $jsonData["msp"]["contents"]["items"];
				thisClass.courseList = [];
				if(res){
					if(!res.length){
						res = new Array(res);	
					}
					
					for(var i=0;i<res.length;++i){
						var obj = res;
							thisClass.courseList.push({
								"코스키": obj[i].course__seq
								, "코스명": obj[i].course__name
								, "홀갯수": obj[i].hole__cnt
							});
					}
				}
				$(thisClass).trigger("evtFinishCourseSelect");
			}, function($err) {
				alert($err);
			});
		}
		/*------------------------- 홀정보 -------------------------*/
		, getHoleImage: function(){
			var thisClass = this;
			var objJson = new MJson();
			var cm = new ConnectionManager();
			
			objJson.putPub(MJson.PUB.SID, "KB001");
			objJson.putPub(MJson.PUB.SERVICENAME, "getNationalGolfclubHoleList");
			
			objJson.putParameter("course_seq", this.getSearchRequest("코스키"));
			objJson.putParameter("hole_no", this.getSearchRequest("홀"));
			
			cm.requestGet(objJson.getJsonString(), function($jsonData){
				
				var res = $jsonData["msp"]["contents"]["items"];
				thisClass.holeList = [];
				if(res){
					if(!res.length){
						res = new Array(res);	
					}
					
					for(var i=0;i<res.length;++i){
						var obj = res;
							thisClass.holeList.push({
								"경로": obj[i].path
								, "저장파일명": obj[i].save__file__name
								, "원본파일명": obj[i].orgn__file__name
								, "파": obj[i].par
								, "이미지": obj[i].path+obj[i].save__file__name
							});
					}
				}
				$(thisClass).trigger("evtFinishHoleImage");
			}, function($err) {
				alert($err);
			});
		}
		, getAreaSelectData: function(){
			return this.areaList;
		}
		, getGolfSelectData: function(){
			return this.golfList;
		}
		, getCourseSelectData: function(){
			return this.courseList;
		}
		, getHoleSelectData: function(){
			return this.holeList;
		}
		, setSearchRequest: function(key,val){
			this.searchRequest[key]=val;
		}
		, getSearchRequest: function(key){
			return this.searchRequest[key];
		}
	}
	
	function clsCourseSelectList(){
		this.imageData = null;
		this._HTMLDom = null;
		this._init();
	}
	
	clsCourseSelectList.prototype = {
		_init: function(){
			var $layer = $("section#course_write section ul");
			this._HTMLDom = {
				"$layer" : $layer
				, "$areaElement": $layer.find("div.golf_co div.ui-block-a")
				, "$golfElement": $layer.find("div.golf_co div.ui-block-b")
				, "$courseElement": $layer.find("div.hall_co div.ui-block-a")
				, "$holeElement": $layer.find("div.hall_co div.ui-block-b")
			}
			this.imageData = [];
		}
		/*============================== 권역 SelectBox View ==============================*/
		,setAreaList: function(thisData){
			var $layer = this._HTMLDom["$layer"];
			var $areaElement = this._HTMLDom["$areaElement"];
			var $golfElement = this._HTMLDom["$golfElement"];
			var $courseElement = this._HTMLDom["$courseElement"];
			var $holeElement = this._HTMLDom["$holeElement"];
			
			
			$areaElement.find("select").empty();
			$golfElement.find("select").empty();
			$courseElement.find("select").empty();
			$holeElement.find("select").empty();
			
			this.setSelectInit();
			
			for(var i=0;i<thisData.length;i++){
				$areaElement.find("select").append("<option value='" + i + "'>" + thisData[i]["지역정보명"] + "</option>");
			}
			
			this._HTMLDom["$layer"].find("select").selectmenu("refresh");
		}
		/*============================== 골프장 SelectBox View ==============================*/
		, setGolfList: function(thisData){
			var $layer = this._HTMLDom["$layer"];
			var $golfElement = this._HTMLDom["$golfElement"];
			var $courseElement = this._HTMLDom["$courseElement"];
			var $holeElement = this._HTMLDom["$holeElement"];
			
			$golfElement.find("select").empty();
			$courseElement.find("select").empty();
			$holeElement.find("select").empty();
			
			this.setSelectInit();
			
			for(var i=0;i<thisData.length;i++){
				$golfElement.find("select").append("<option value='" + i + "'>" + thisData[i]["골프장명"] + "</option>");
			}

			this._HTMLDom["$layer"].find("select").selectmenu("refresh");
		}
		/*============================== 코스 SelectBox View ==============================*/
		, setCourseList: function(thisData){
			var $courseElement = this._HTMLDom["$courseElement"];
			var $holeElement = this._HTMLDom["$holeElement"];
			
			$courseElement.find("select").empty();
			$holeElement.find("select").empty();
			
			this.setSelectInit();
			
			for(var i=0;i<thisData.length;i++){
				$courseElement.find("select").append("<option value='" + i + "'>" + thisData[i]["코스명"] + "</option>");
			}
			
			this._HTMLDom["$layer"].find("select").selectmenu("refresh");
		}
		/*============================== 홀 SelectBox View ==============================*/
		, setHoleList: function(thisData){
			var $element = this._HTMLDom["$holeElement"];
			$element.find("select").empty();
			
			this.setSelectInit();
			
			for(var i=1;i<=thisData;i++){
				$element.find("select").append("<option value='" + i + "'>" + i + "</option>");
			}
			
			this._HTMLDom["$layer"].find("select").selectmenu("refresh");
		}
		
		, setSelectInit: function(){
				var $areaElement = this._HTMLDom["$areaElement"].find("select");
				var $golfElement = this._HTMLDom["$golfElement"].find("select");
				var $courseElement = this._HTMLDom["$courseElement"].find("select");
				var $holeElement = this._HTMLDom["$holeElement"].find("select");
				
				if($areaElement.find("option").length < 1){
					$areaElement.append("<option value=''>권역 선택</option>");
					$areaElement.find("option:eq(0)").prop("selected", true);
				}
				
				if($golfElement.find("option").length < 1){
					$golfElement.append("<option value=''>골프장 선택</option>");
					$golfElement.find("option:eq(0)").prop("selected", true);
				}
				if($courseElement.find("option").length < 1){
					$courseElement.append("<option value=''>코스 선택</option>");
					$courseElement.find("option:eq(0)").prop("selected", true);
				}
				if($holeElement.find("option").length < 1){
					$holeElement.append("<option value=''>홀 선택</option>");
					$holeElement.find("option:eq(0)").prop("selected", true);
				}
		}
		/*============================== 홀 이미지 View ==============================*/
		, setHoleImage: function(thisData){
			var $element = this._HTMLDom["$layer"].find("li:eq(1) div.img_input");
			this.imageData = thisData;
			
			$element.find("img").attr("src", _util.nvl(thisData[0]["이미지"]).replace('/data/msp300/dl/files/free/admin/notice', 'http://www.golfinsns.com/_course_super_img/'));
			
		}
		/*============================== 홀 이미지 삭제 ==============================*/
		, deleteHoleImage: function(){
			var $element = this._HTMLDom["$layer"].find("li:eq(1) div.img_input");
			this.imageData = [];
			
			$element.find("img").attr("src", "../images/default_120_120.gif");
			
		}
		, $getLayer: function(){
			return this._HTMLDom["$layer"];
		}
		, $getAreaSelectObj: function(){
			return this._HTMLDom["$areaElement"].find("select");
		}
		, $getGolfSelectObj: function(){
			return this._HTMLDom["$golfElement"].find("select");
		}
		, $getCourseSelectObj: function(){
			return this._HTMLDom["$courseElement"].find("select");
		}
		, $getHoleSelectObj: function(){
			return this._HTMLDom["$holeElement"].find("select");
		}
		, $getCheckBoxObj: function(){
			return this._HTMLDom["$layer"].find("li:eq(0)");
		}
	}
	
//	$(document).bind("pageinit", function(event){
//		
//		var path = String(document.location);
//		if(path.indexOf("navi.html") == -1){
//			document.objControl = new CourseWrite();
//			document.objControl.onPageShow();	
//		}
//	});